package org.jeecg.modules.htxincailiao.news.entity;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.math.BigDecimal;
import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.jeecg.common.util.oConvertUtils;
import org.springframework.format.annotation.DateTimeFormat;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.jeecg.common.aspect.annotation.Dict;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * @Description: ht_news
 * @Author: jeecg-boot
 * @Date:   2022-12-10 10:32:40
 * @Version: V1.0
 */
@Data
@TableName("ht_news")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="ht_news对象", description="ht_news")
public class HTNews implements Serializable {
    private static final long serialVersionUID = 1L;

	/**id*/
	@TableId(type = IdType.ASSIGN_ID)
    @ApiModelProperty(value = "id")
    private String id;

    /**demandType，字典值demand_type*/
    @ApiModelProperty(value = "demandType")
    private String demandType;

    /**demandAll*/
    @ApiModelProperty(value = "demandAll")
    @TableField(exist = false)
    private String demandAll;

	/**分类ID*/
	@Excel(name = "分类", width = 15, dictTable = "ht_news_category", dicText = "name", dicCode = "id")
	@Dict(dictTable = "ht_news_category", dicText = "name", dicCode = "id")
    @ApiModelProperty(value = "分类ID")
    private String categoryId;
	/**标题*/
	@Excel(name = "标题", width = 15)
    @ApiModelProperty(value = "标题")
    private String name;
	/**副标题*/
	@Excel(name = "副标题", width = 15)
    @ApiModelProperty(value = "副标题")
    private String subname;
	/**点击量*/
	@Excel(name = "点击量", width = 15)
    @ApiModelProperty(value = "点击量")
    private Integer clickCount;
	/**文档来源类型（0-原创，1-转载）*/
	@Excel(name = "文档来源类型", width = 15, dicCode = "source_type")
	@Dict(dicCode = "source_type")
    @ApiModelProperty(value = "文档来源类型（0-原创，1-转载）")
    private Integer sourceType;
	/**排序*/
	@Excel(name = "排序", width = 15)
    @ApiModelProperty(value = "排序")
    private Integer sort;
	/**首页排序*/
	@Excel(name = "首页排序", width = 15)
    @ApiModelProperty(value = "首页排序")
    private Integer homeSort;
	/**文档来源*/
	@Excel(name = "文档来源", width = 15)
    @ApiModelProperty(value = "文档来源")
    private String source;
	/**采集站点*/
	@Excel(name = "采集站点", width = 15)
    @ApiModelProperty(value = "采集站点")
    private String site;
	/**主图*/
	@Excel(name = "主图", width = 15)
    @ApiModelProperty(value = "主图")
    private String cover;
	/**详细描述*/
	//@Excel(name = "详细描述", width = 15)
    @ApiModelProperty(value = "详细描述")
    private String content;

    /**SEO关键字*/
    @Excel(name = "SEO关键字", width = 15)
    @ApiModelProperty(value = "SEO关键字")
    private String seoKeywords;


    /**SEO描述*/
    @Excel(name = "SEO描述", width = 15)
    @ApiModelProperty(value = "SEO描述")
    private String seoDescription;


    @TableField(exist = false)
    private Object[] categoryInfos;


    /**附件*/
    @Excel(name = "附件", width = 15)
    @ApiModelProperty(value = "附件")
    private String attachments;


    @TableField(exist = false)
    private Object[] attachmentList;
    public Object[] getAttachmentList() {
        if (oConvertUtils.isNotEmpty(attachments)){
            List<Object> list = new ArrayList<Object>();

            String[] items = attachments.split(",");
            for (String filePath: items){
                String targetFileName = "";
                String suffix = "";
                String fileNameNoSuffix = "";
                String[] slices = filePath.split("/");
                if(oConvertUtils.isNotEmpty(slices) && slices.length>0){
                    String fileName = slices[slices.length-1];
                    if(oConvertUtils.isNotEmpty(fileName)){
                        String[] nameSlices = fileName.split("_");
                        if (oConvertUtils.isNotEmpty(nameSlices) && nameSlices.length >0){
                            targetFileName = nameSlices[0] ;
                             fileNameNoSuffix = nameSlices[0] ;
                        }

                        String[] nameSlicesFromDot = fileName.split("\\.");
                        if (oConvertUtils.isNotEmpty(nameSlicesFromDot) && nameSlicesFromDot.length >0){
                            suffix += nameSlicesFromDot[nameSlicesFromDot.length-1];
                            targetFileName = targetFileName +"."+ suffix;
                        }
                    }
                }

                JSONObject fileInfo = new JSONObject();
                fileInfo.put("suffix", suffix);
                fileInfo.put("src", filePath);
                fileInfo.put("fileName", targetFileName);
                fileInfo.put("fileNameNoSuffix", fileNameNoSuffix);

                list.add(fileInfo);
            }
            return list.toArray();
        }

        return null;
    }

	/**是否为首页推荐 0-不推荐 1-推荐*/
	@Excel(name = "是否为首页推荐", width = 15, dicCode = "is_home_recommended")
	@Dict(dicCode = "is_home_recommended")
    @ApiModelProperty(value = "是否为首页推荐 0-不推荐 1-推荐")
    private Integer isHomeRecommended;
	/**状态：0-未审核 1-审核中 2-已通过 3-已驳回*/
	@Excel(name = "状态", width = 15, dicCode = "audit_status")
	@Dict(dicCode = "audit_status")
    @ApiModelProperty(value = "状态：0-未审核 1-审核中 2-已通过 3-已驳回")
    private Integer auditStatus;
	/**审批意见*/
	@Excel(name = "审批意见", width = 15)
    @ApiModelProperty(value = "审批意见")
    private String auditComments;
	/**逻辑删除：0-未删除,1-删除。*/
    @ApiModelProperty(value = "逻辑删除：0-未删除,1-删除。")
    private Integer isDeleted;
	/**创建人*/
    @ApiModelProperty(value = "创建人")
    private String createBy;
	/**创建时间*/
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "创建时间")
    private Date createTime;
	/**更新人*/
    @ApiModelProperty(value = "更新人")
    private String updateBy;
	/**更新时间*/
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "更新时间")
    private Date updateTime;

    @TableField(exist = false)
    private Integer pageNo=1;

    @TableField(exist = false)
    private Integer pageSize=10;
}
